<!-- 新增弹窗 -->

<template>
  <WebModal path="add" small>
    <WebForm path="add">
      <FormInput label="任务名称" bind="taskName" :max="6" required />

      <FormSelect label="循环模式" bind="playModeId, playModelName" :dict="DICT.LOOP" required />

      <EasyRow col2>
        <FormNum label="任务音量" bind="volume" :min="0" :max="100" initMin noTip />
        <FormNum label="优先级" bind="level" :min="1" :max="999" initMin noTip />
      </EasyRow>

      <FormSelectMulti label="终端设备" bind="terminalIdList" :dict="terminal_selectDict" @change="changeTerminal" />

      <FormSelectMulti label="音乐文件" bind="musicIdList" :dict="music_selectDict" @change="changeMusic" />
    </WebForm>
  </WebModal>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'AddModal',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb('add'), CORE.mixSelect('terminal', 'terminal_'), CORE.mixSelect('music', 'music_')],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 切换终端
     */
    changeTerminal(idList = []) {
      this.one.terminalList = idList.map((id) => this.terminal_select.find((item) => item.id === id))
    },

    /**
     * 切换音乐
     */
    changeMusic(idList = []) {
      this.one.musicList = idList.map((id) => this.music_select.find((item) => item.id === id))
    },
  },
}
</script>
